package com.lianxian.xindong.me.mvp.ui.holder;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.android.library.YLCircleImageView;
import com.hxb.library.base.BaseHolder;
import com.hxb.library.di.component.AppComponent;
import com.hxb.library.http.imageloader.ImageLoader;
import com.hxb.library.utils.HxbUtils;
import com.lianxian.xindong.commonres.weight.SquareImageView;
import com.lianxian.xindong.commonsdk.BuildConfig;
import com.lianxian.xindong.commonsdk.imgaEngine.config.CommonImageConfigImpl;
import com.lianxian.xindong.me.R;
import com.lianxian.xindong.me.R2;

import butterknife.BindView;

/**
 * @author: HeXingBo
 * @date: 2022/11/15
 * @description：
 */
public class PraiseToMeItemHolder extends BaseHolder<Object> {

    @BindView(R2.id.iv_user_head)
    YLCircleImageView ivUserHead;
    @BindView(R2.id.tv_user_nice)
    TextView tvUserNice;
    @BindView(R2.id.tv_time)
    TextView tvTime;
    @BindView(R2.id.lv_nice)
    LinearLayout lvNice;
    @BindView(R2.id.tv_address_and_role)
    TextView tvAddressAndRole;
    @BindView(R2.id.lv_hobby)
    LinearLayout lvHobby;
    @BindView(R2.id.iv_praise)
    ImageView ivPraise;
    @BindView(R2.id.iv_on_line)
    ImageView ivOnLine;
    @BindView(R2.id.tv_user_sex_and_age)
    TextView tvUserSexAndAge;
    @BindView(R2.id.tv_hobby)
    TextView tvHobby;


    private AppComponent mAppComponent;
    private ImageLoader mImageLoader;//用于加载图片的管理类,默认使用 Glide,使用策略模式,可替换框架

    public PraiseToMeItemHolder(View itemView) {
        super(itemView);
        //可以在任何可以拿到 Context 的地方,拿到 AppComponent,从而得到用 Dagger 管理的单例对象
        mAppComponent = HxbUtils.obtainAppComponentFromContext(itemView.getContext());
        mImageLoader = mAppComponent.imageLoader();
    }

    @Override
    public void setData(@NonNull Object data, int position) {
        tvUserNice.setText("nice" + (position + 1));
        tvUserSexAndAge.setText(position + "");
        tvAddressAndRole.setText("重庆·老师");
        tvHobby.setText("游泳 唱歌");
        //itemView 的 Context 就是 Activity, Glide 会自动处理并和该 Activity 的生命周期绑定
        mImageLoader.loadImage(itemView.getContext(),
                CommonImageConfigImpl.builder()
                        .url(TextUtils.isEmpty("url") ? BuildConfig.DEFAULT_HEAD_URL : "url")
                        .errorPic(R.drawable.ic_defunct_head)
                        .placeholder(R.drawable.ic_defunct_head)
                        .imageRadius(10)
                        .imageView(ivUserHead)
                        .build());
    }

    @Override
    protected void onRelease() {
        mImageLoader.clear(mAppComponent.application(), CommonImageConfigImpl.builder()
                .imageViews(ivUserHead)
                .build());
    }
}